package login.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lion.common.MsgCodeAnn;
import lion.netty4.message.GamePlayer;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lion.netty4.processor.MsgProcessor;
import login.logic.LoginAccountManager;
import lua.LuaMessageLogin.C2SOpenLogin;

@MsgCodeAnn(msgcode = C2SOpenLogin.id, accessLimit = 200)
public class OpenLoginProcessor extends MsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(OpenLoginProcessor.class);

	private LoginAccountManager loginAccountManager = LoginAccountManager.getInstance();

	@Override
	public void process(GamePlayer player, RequestMessageRaw request) throws Exception {
		C2SOpenLogin reqMsg = C2SOpenLogin.parse(request);
		String code = reqMsg.code;
		String access_token = reqMsg.access_token;
		logger.info("1003-open-login,code={},access_token={},addr={}", code, access_token,
				player.getAddress());
		loginAccountManager.loginWeiXin(player, code, access_token);
	}

	@Override
	public void process(GamePlayer player, RequestProtoMessage request) throws Exception {
	}

	@Override
	public void process(GamePlayer player, MyRequestMessage request) throws Exception {
	}

}
